/**
 * @ClassName ComicAdapter
 * @Author 24
 * @Date 2023/5/10 14:34
 * @Version 1.0.0
 * freedom is the oxygen of the soul.
 **/

package cn.edu.nchu.comic_strip.ui.bookpage;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;


import java.util.List;

import cn.edu.nchu.comic_strip.entity.Page;

public class BookPageAdapter extends FragmentStatePagerAdapter {

    private List<Page> comicData;
    private int textSizeIndex;
    private BookPageActivity activity;
    private boolean isProtect;

    public BookPageAdapter(FragmentManager fm, List<Page> comicData, int textSizeIndex, BookPageActivity activity,boolean isProtect) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.comicData = comicData;
        this.textSizeIndex = textSizeIndex;
        this.activity = activity;
        this.isProtect = isProtect;
    }


    public void setTextSizeIndex(int textSizeIndex) {
        this.textSizeIndex = textSizeIndex;
    }

    @Override
    public Fragment getItem(int position) {
        BookPageFragment fragment = new BookPageFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("comicData", comicData.get(position));   // 获取数据类
        bundle.putInt("sumPages", comicData.size()-1);    // 获取总页数
        bundle.putInt("textSizeIndex", textSizeIndex);  // 获取字体大小索引
        bundle.putBoolean("isProtect", isProtect);  // 获取是否保护
        fragment.setArguments(bundle);
        fragment.setButtonClickListener(activity);
        return fragment;
    }
    
    @Override
    public int getCount() {
        return comicData.size();
    }

    public boolean isProtect() {
        return isProtect;
    }

    public void setProtect(boolean protect) {
        isProtect = protect;
    }
}
